﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MaquinaJMG.GUI.Contrato;
using MaquinaJMG.GUI.Presentador;

using Dolinay;
using System.IO;

namespace MaquinaJMG.GUI.Vista
{

    public partial class PendriveImportar : Form,IContratoLeerXML
    {   
        private bool Flag=false;
        private PresentadorLeerXML _presentadorImportar;
        private DriveDetector driveDetector = null;
        string ruta;
        Login _anterior;
        public PendriveImportar(Login anterior)
        {
            this.Visible = true;
            _anterior = anterior;
            InitializeComponent();
            driveDetector = new DriveDetector();
            driveDetector.DeviceArrived += new DriveDetectorEventHandler(OnDriveArrived);
            driveDetector.DeviceRemoved += new DriveDetectorEventHandler(OnDriveRemoved);
            driveDetector.QueryRemove += new DriveDetectorEventHandler(OnQueryRemove);
            _presentadorImportar = new PresentadorLeerXML();
        }

        // Called by DriveDetector when removable device in inserted 
        private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
        {
            // Report the event in the listbox.
            // e.Drive is the drive letter for the device which just arrived, e.g. "E:\\"
            string Ruta = e.Drive;
            _presentadorImportar.leer(Ruta);
            _presentadorImportar.leer2(Ruta);
            MessageBox.Show("Importacion Realizada con Exito, el sistema se Reiniciara", "Advertencia",
                    MessageBoxButtons.OK, MessageBoxIcon.Question);
            this.SetVisibleCore(false);
            Flag = true;
            Application.Restart();
            
            //listBox1.Items.Add(s);

            // If you want to be notified when drive is being removed (and be able to cancel it), 
            // set HookQueryRemove to true 
           // if ( checkBoxAskMe.Checked )   
             //   e.HookQueryRemove = true;                 
        }

        // Called by DriveDetector after removable device has been unpluged 
        private void OnDriveRemoved(object sender, DriveDetectorEventArgs e)
        {
            // TODO: do clean up here, etc. Letter of the removed drive is in e.Drive;
            
            // Just add report to the listbox
            if(!Flag)
            MessageBox.Show("Importacion Fallida", "Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Question);
            //string Ruta = "Drive removed " + e.Drive;
            //listBox1.Items.Add(s);
        }

        // Called by DriveDetector when removable drive is about to be removed
        private void OnQueryRemove(object sender, DriveDetectorEventArgs e)
        {
        }
        

        // User checked the "Ask me before drive can be disconnected box"        
        private void checkBoxAskMe_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ConfigurarMaquina proxima = new ConfigurarMaquina(this);
            proxima.Visible = true;
            this.Visible = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            _anterior.Visible = true;
            this.Dispose(true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            exportarApuestas proxima = new exportarApuestas(this);
            this.Visible=false;
            proxima.Visible=true;
        }
    }
}